home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 5.2 KB | 181 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/17/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPConfirmTask
-
- SUPERCLASS: CPPPeriodicTask
-
- This class lets you asynchronously confirm the address of
- a node on the network
-
- ********************************************************************/
-
- #include <CPPConfirmTask.h>
- #include <CPPTaskManager.h>
- #include <CPPNodeInfo.h>
- #include <MemoryTools.h>
-
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPConfirmTask::CPPConfirmTask (CPPTaskManager *TaskManager,
- long minPeriod,
- Boolean deleteWhenDone) :
- CPPPeriodicTask (TaskManager, minPeriod,
- deleteWhenDone)
- {
- this->confirmRec = NULL;
- this->confirmAddr = NULL;
- this->NodeToConfirm = NULL;
- this->NTE = NULL;
- this->foundIt = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPConfirmTask::~CPPConfirmTask (void)
- {
- MPPParamBlock killPB;
- OSErr ErrCode;
-
- if (this->confirmRec)
- // cancel the confirm call, if there is one pending
- if (this->confirmRec->MPPioResult == 1)
- {
- killPB.NBPnKillQEl = (Ptr)&confirmRec->MPP.qLink;
- ErrCode = PKillNBP(&killPB, false);
- }
-
- if (this->NodeToConfirm)
- delete this->NodeToConfirm;
- NukePtr(this->confirmRec);
- NukePtr(this->confirmAddr);
- NukePtr(this->NTE);
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPConfirmTask::ClassName (void)
- {
- return "CPPConfirmTask";
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmTask::StartNodeConfirm (CPPNodeInfo *TheNode,
- CompletionProc DoProc)
- /* this routine sets all the initial values for the lookup task */
- /* and then sends it to the manager to be queued for execution */
- {
- // exit if this task is still involved in a lookup
- // our have no manager
- if ((!this->hasCompleted) || (!this->ourManager))
- return;
-
- // otherwise, set up the call
- // first allocate the structures we will use
- this->confirmRec = (MPPParamBlock *)NewPtrClear(sizeof(MPPParamBlock));
- if ((this->callResult = MemError()) != noErr) return;
-
- this->NTE = (NamesTableEntry *)NewPtrClear(sizeof(NamesTableEntry));
- if ((this->callResult = MemError()) != noErr) return;
-
- this->confirmAddr = (AddrBlock *)NewPtrClear(sizeof(AddrBlock));
- if ((this->callResult = MemError()) != noErr) return;
-
- if (this->NodeToConfirm)
- delete this->NodeToConfirm;
-
- this->NodeToConfirm = (CPPNodeInfo *)TheNode->Clone();
- this->SetCompletionProc(DoProc);
- this->hasCompleted = FALSE; // note that we are not done
-
- SetupConfirmCall(TheNode);
-
- if (this->callResult == noErr)
- this->ourManager->AddPeriodicTask(this); // now add the task
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmTask::DoPeriodicAction (void)
- /* if the lookup call has completed, extract the nodes and */
- /* execute another lookup call, unless we have gotten all the nodes */
- /* in which case, set the hasCompleted flag */
- {
- // call the inherited method to update frequency count
- CPPPeriodicTask::DoPeriodicAction();
-
- // do our periodic task
- switch (this->confirmRec->MPPioResult) {
- case noErr : // the call has completed
- this->foundIt = TRUE;
- this->hasCompleted = TRUE;
- this->callResult = noErr;
- break;
-
- case 1 : // still busy finding the name
- break;
-
- default : // an error occurred
- this->callResult = confirmRec->MPPioResult;
- this->foundIt = FALSE;
- hasCompleted = TRUE;
- break;
- }
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmTask::DoCompletedAction(void)
- /* delete the structures we allocated to do the lookup */
- {
- NukePtr(this->confirmRec);
- NukePtr(this->confirmAddr);
- NukePtr(this->NTE);
-
- CPPPeriodicTask::DoCompletedAction();
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPConfirmTask::NodeExists (Boolean *isDone)
- {
- return this->foundIt;
- }
-
- /*-----------------------------------------------------------------*/
- /*---------------------- PROTECTED MEMEBERS -----------------------*/
- /*-----------------------------------------------------------------*/
-
- void CPPConfirmTask::SetupConfirmCall (CPPNodeInfo *TheNode)
- {
- StringPtr ObjStr, TypeStr, ZoneStr;
- short SNum, NNum, ZNum;
-
- // extract the address of the node we want to confirm
- TheNode->GetNodeAddress (&SNum, &NNum, &ZNum);
- confirmAddr->aSocket = SNum;
- confirmAddr->aNode = NNum;
- (short)confirmAddr->aNet = ZNum;
-
- // construct the name we want to confirm
- TheNode->GetNodeName (&ObjStr, &TypeStr, &ZoneStr);
- NBPSetEntity((Ptr)NTE->nt.entityData, (Ptr)ObjStr,
- (Ptr)TypeStr, (Ptr)ZoneStr);
-
- // set up the call record
- confirmRec->MPPioCompletion = NULL;
- confirmRec->NBPentityPtr = (Ptr)&NTE->nt.entityData;
- confirmRec->NBPinterval = 2;
- confirmRec->NBPcount = 3;
- confirmRec->NBPconfirmAddr = *confirmAddr;
-
- // make the call synchronously
- this->callResult = PConfirmName(confirmRec,TRUE);
- }
-